﻿using System;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Collections;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Microsoft.Reporting.WebForms;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace dcwj
{
    public partial class bcdbPage : System.Web.UI.Page
    {
        private String M_CONSTR = ConfigurationManager.ConnectionStrings["dcwjConnectionString"].ToString();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    //PaperList pl = (PaperList)Context.Handler;
                    ArrayList ar = Session["selList"] as ArrayList;
           
                    if (ar == null) Response.Redirect("");
                    Database objDB = new SqlDatabase(M_CONSTR);
                    
                    DataSet dsAllClass = new DataSet();
                    DataSet dsAllClass1 = new DataSet();
                    DataSet dsAllClass2 = new DataSet();
                    DataSet dsAllClass3 = new DataSet();
                    DataSet dsAllClass4 = new DataSet();
                    DataSet dsTeacherClass = new DataSet();

                    for (int i = 0; i < ar.Count; i++)
                    {

                        DataSet dsClass = objDB.ExecuteDataSet(CommandType.Text, @"select 
					p.PaperName,
                    a.课程内容,
                    b.培训方法,
                    c.关于讲师,
                    d.培训组织
                    from
					
					(SELECT PaperName from Table_PAPER where paperid =" + ar[i].ToString() + @") as p,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as 课程内容
                      FROM Table_RESULT
                    where paperid =" + ar[i].ToString() + @" and Qid in(1,2,3,4,5)) as a,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as 培训方法
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(6,7,8)) as b,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as 关于讲师
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(9,10,11,12,13)) as c,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as 培训组织
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(14,15,16,17)) as d");

                        dsAllClass.Merge(dsClass);


                        DataSet dsClass1 = objDB.ExecuteDataSet(CommandType.Text, @"select 
					p.PaperName,
                    a.q1,
                    b.q2,
                    c.q3,
                    d.q4,
					e.q5
                    from
					
					(SELECT PaperName from Table_PAPER where paperid =" + ar[i].ToString() + @") as p,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q1
                      FROM Table_RESULT
                    where paperid =" + ar[i].ToString() + @" and Qid in(1)) as a,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q2
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(2)) as b,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q3
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(3)) as c,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q4
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(4)) as d,


                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q5
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(5)) as e");

                        dsAllClass1.Merge(dsClass1);


                        DataSet dsClass2 = objDB.ExecuteDataSet(CommandType.Text, @"select 
					p.PaperName,
                    a.q6,
                    b.q7,
                    c.q8
                 
                    from
					
					(SELECT PaperName from Table_PAPER where paperid =" + ar[i].ToString() + @") as p,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q6
                      FROM Table_RESULT
                    where paperid =" + ar[i].ToString() + @" and Qid in(6)) as a,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q7
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(7)) as b,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q8
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(8)) as c");

                        dsAllClass2.Merge(dsClass2);


                        DataSet dsClass3 = objDB.ExecuteDataSet(CommandType.Text, @"select 
					p.PaperName,
                    a.q9,
                    b.q10,
                    c.q11,
                    d.q12,
					e.q13
                    from
					
					(SELECT PaperName from Table_PAPER where paperid =" + ar[i].ToString() + @") as p,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q9
                      FROM Table_RESULT
                    where paperid =" + ar[i].ToString() + @" and Qid in(9)) as a,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q10
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(10)) as b,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q11
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(11)) as c,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q12
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(12)) as d,


                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q13
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(13)) as e");

                        dsAllClass3.Merge(dsClass3);


                        DataSet dsClass4 = objDB.ExecuteDataSet(CommandType.Text, @"select 
					p.PaperName,
                    a.q14,
                    b.q15,
                    c.q16,
                    d.q17
                    from
					
					(SELECT PaperName from Table_PAPER where paperid =" + ar[i].ToString() + @") as p,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q14
                      FROM Table_RESULT
                    where paperid =" + ar[i].ToString() + @" and Qid in(14)) as a,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q15
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(15)) as b,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q16
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(16)) as c,

                    (SELECT 
                    avg(cast (QAnswer as decimal)) as q17
                      FROM Table_RESULT
                    where paperid = " + ar[i].ToString() + @" and Qid in(17)) as d");

                        dsAllClass4.Merge(dsClass4);
                    }


                    bcdb ds = new bcdb();
                    for (int j = 0; j < ar.Count; j++)
                    {
                        DataSet dsTmp = objDB.ExecuteDataSet(CommandType.Text, @"select 
t.TeacherName,
p.PaperName from Table_PAPER p, Table_TEACHER t
where p.PaperID=" + ar[j].ToString() + " and p.teacherid = t.teacherid");
                        ds.TeacherClass.AddTeacherClassRow(dsTmp.Tables[0].Rows[0][0].ToString(),
                            dsTmp.Tables[0].Rows[0][1].ToString());
                    }

                    if (dsAllClass != null && dsAllClass.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dsAllClass.Tables[0].Rows.Count; i++)
                        {
                            ds.bcdbzt.AddbcdbztRow("课程内容",
                                dsAllClass.Tables[0].Rows[i][1].ToString(),
                                dsAllClass.Tables[0].Rows[i][0].ToString());
                            ds.bcdbzt.AddbcdbztRow("培训方法",
                             dsAllClass.Tables[0].Rows[i][2].ToString(),
                             dsAllClass.Tables[0].Rows[i][0].ToString());
                            ds.bcdbzt.AddbcdbztRow("关于讲师",
                             dsAllClass.Tables[0].Rows[i][3].ToString(),
                             dsAllClass.Tables[0].Rows[i][0].ToString());
                            ds.bcdbzt.AddbcdbztRow("培训组织",
                             dsAllClass.Tables[0].Rows[i][4].ToString(),
                             dsAllClass.Tables[0].Rows[i][0].ToString());
                        }
                    }

                    if (dsAllClass1 != null && dsAllClass1.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dsAllClass1.Tables[0].Rows.Count; i++)
                        {
                            ds.bcdb1.Addbcdb1Row("适合我的知识水平（针对性）",
                                dsAllClass1.Tables[0].Rows[i][1].ToString(),
                                dsAllClass1.Tables[0].Rows[i][0].ToString());
                            ds.bcdb1.Addbcdb1Row("对我实际工作有帮助（实用性）",
                             dsAllClass1.Tables[0].Rows[i][2].ToString(),
                             dsAllClass1.Tables[0].Rows[i][0].ToString());
                            ds.bcdb1.Addbcdb1Row("能够给我启发 （启发性）",
                             dsAllClass1.Tables[0].Rows[i][3].ToString(),
                             dsAllClass1.Tables[0].Rows[i][0].ToString());
                            ds.bcdb1.Addbcdb1Row("包含足够多针对主题的信息（完整性）",
                             dsAllClass1.Tables[0].Rows[i][4].ToString(),
                             dsAllClass1.Tables[0].Rows[i][0].ToString());
                            ds.bcdb1.Addbcdb1Row("内容时新（时效性）",
                             dsAllClass1.Tables[0].Rows[i][5].ToString(),
                             dsAllClass1.Tables[0].Rows[i][0].ToString());
                        }
                    }


                    if (dsAllClass2 != null && dsAllClass2.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dsAllClass2.Tables[0].Rows.Count; i++)
                        {
                            ds.bcdb2.Addbcdb2Row("分组练习、案例研讨、角色扮演的课堂活动有助于课程学习",
                                dsAllClass2.Tables[0].Rows[i][1].ToString(),
                                dsAllClass2.Tables[0].Rows[i][0].ToString());
                            ds.bcdb2.Addbcdb2Row("师生互动交流的教学形式有助于课程学习",
                             dsAllClass2.Tables[0].Rows[i][2].ToString(),
                             dsAllClass2.Tables[0].Rows[i][0].ToString());
                            ds.bcdb2.Addbcdb2Row("多种教学媒体（白板纸、投影仪、演示音视频）的使用有助于课程学习",
                             dsAllClass2.Tables[0].Rows[i][3].ToString(),
                             dsAllClass2.Tables[0].Rows[i][0].ToString());
                        }
                    }


                    if (dsAllClass3 != null && dsAllClass3.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dsAllClass3.Tables[0].Rows.Count; i++)
                        {
                            ds.bcdb3.Addbcdb3Row("讲解能够围绕课程主题，有单元小结",
                                dsAllClass3.Tables[0].Rows[i][1].ToString(),
                                dsAllClass3.Tables[0].Rows[i][0].ToString());
                            ds.bcdb3.Addbcdb3Row("能够合理安排课程讲解和课堂活动时间",
                             dsAllClass3.Tables[0].Rows[i][2].ToString(),
                             dsAllClass3.Tables[0].Rows[i][0].ToString());
                            ds.bcdb3.Addbcdb3Row("经常提问引导学员学习，活跃课堂气氛",
                             dsAllClass3.Tables[0].Rows[i][3].ToString(),
                             dsAllClass3.Tables[0].Rows[i][0].ToString());
                            ds.bcdb3.Addbcdb3Row("授课热情、认真",
                             dsAllClass3.Tables[0].Rows[i][4].ToString(),
                             dsAllClass3.Tables[0].Rows[i][0].ToString());
                            ds.bcdb3.Addbcdb3Row("专业知识丰富，解答准确",
                             dsAllClass3.Tables[0].Rows[i][5].ToString(),
                             dsAllClass3.Tables[0].Rows[i][0].ToString());
                        }
                    }


                    if (dsAllClass4 != null && dsAllClass4.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dsAllClass4.Tables[0].Rows.Count; i++)
                        {
                            ds.bcdb4.Addbcdb4Row("培训环境利于学习（上课场地、教学环境）",
                                dsAllClass4.Tables[0].Rows[i][1].ToString(),
                                dsAllClass4.Tables[0].Rows[i][0].ToString());
                            ds.bcdb4.Addbcdb4Row("后勤组织保障到位（用餐、住宿）",
                             dsAllClass4.Tables[0].Rows[i][2].ToString(),
                             dsAllClass4.Tables[0].Rows[i][0].ToString());
                            ds.bcdb4.Addbcdb4Row("教学设备能够满足学员需求（桌椅）",
                             dsAllClass4.Tables[0].Rows[i][3].ToString(),
                             dsAllClass4.Tables[0].Rows[i][0].ToString());
                            ds.bcdb4.Addbcdb4Row("培训材料、工具能够满足学员需求（资料、纸、笔）",
                             dsAllClass4.Tables[0].Rows[i][4].ToString(),
                             dsAllClass4.Tables[0].Rows[i][0].ToString());
                        }
                    }

                    ReportDataSource rds0 = new ReportDataSource("bcdbzt", (DataTable)ds.bcdbzt);
                    ReportDataSource rds1 = new ReportDataSource("bcdb1", (DataTable)ds.bcdb1);
                    ReportDataSource rds2 = new ReportDataSource("bcdb2", (DataTable)ds.bcdb2);
                    ReportDataSource rds3 = new ReportDataSource("bcdb3", (DataTable)ds.bcdb3);
                    ReportDataSource rds4 = new ReportDataSource("bcdb4", (DataTable)ds.bcdb4);
                    ReportDataSource rds5 = new ReportDataSource("TeacherClass", (DataTable)ds.TeacherClass);

                    ReportViewer1.LocalReport.DataSources.Add(rds0);
                    ReportViewer1.LocalReport.DataSources.Add(rds1);
                    ReportViewer1.LocalReport.DataSources.Add(rds2);
                    ReportViewer1.LocalReport.DataSources.Add(rds3);
                    ReportViewer1.LocalReport.DataSources.Add(rds4);
                    ReportViewer1.LocalReport.DataSources.Add(rds5);

                    ReportViewer1.LocalReport.Refresh();

                    Session["selList"] = null;
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
        }
    }
}